package com.gewu.pm.ui.dialog.bean;

import android.text.TextUtils;

/**
 * 业务员数据Bean
 */
public class SalespersonBean {
    private String name;
    private String pinyin;
    private String letter;
    private boolean selected;
    private boolean isHeader; // 是否是分组头部

    /**
     * 普通构造函数（业务员）
     */
    public SalespersonBean(String name) {
        this.name = name;
        this.pinyin = PinyinUtils.getPinyin(name);
        this.letter = PinyinUtils.getFirstLetter(name);
        this.selected = false;
        this.isHeader = false;
    }

    /**
     * 头部构造函数（分组标题）
     */
    public SalespersonBean(String letter, boolean isHeader) {
        this.name = "";
        this.pinyin = "";
        this.letter = letter;
        this.selected = false;
        this.isHeader = isHeader;
    }

    public String getName() {
        return name;
    }

    public String getPinyin() {
        return pinyin;
    }

    public String getLetter() {
        return letter;
    }

    public boolean isSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }

    public boolean isHeader() {
        return isHeader;
    }

    /**
     * 拼音工具类（简化版）
     */
    private static class PinyinUtils {
        /**
         * 获取汉字的拼音
         */
        public static String getPinyin(String name) {
            if (TextUtils.isEmpty(name)) return "";
            // 简化实现：直接使用首字符
            return name;
        }

        /**
         * 获取首字母
         */
        public static String getFirstLetter(String name) {
            if (TextUtils.isEmpty(name)) return "#";

            char firstChar = name.charAt(0);

            // 简化的首字母判断（基于常见姓氏）
            if (firstChar >= 'A' && firstChar <= 'Z') {
                return String.valueOf(firstChar);
            } else if (firstChar >= 'a' && firstChar <= 'z') {
                return String.valueOf(Character.toUpperCase(firstChar));
            }

            // 根据常见姓氏映射首字母
            String letter = getLetterByName(firstChar);
            return letter != null ? letter : "#";
        }

        /**
         * 根据姓氏获取首字母（常见姓氏）
         */
        private static String getLetterByName(char firstChar) {
            switch (firstChar) {
                case '阿': return "A";
                case '安': return "A";
                case '白': return "B";
                case '蔡': return "C";
                case '池': return "C";
                case '陈': return "C";
                case '邓': return "D";
                case '董': return "D";
                case '范': return "F";
                case '冯': return "F";
                case '高': return "G";
                case '郭': return "G";
                case '韩': return "H";
                case '胡': return "H";
                case '黄': return "H";
                case '姜': return "J";
                case '贾': return "J";
                case '李': return "L";
                case '刘': return "L";
                case '马': return "M";
                case '孟': return "M";
                case '欧': return "O";
                case '彭': return "P";
                case '孙': return "S";
                case '王': return "W";
                case '吴': return "W";
                case '张': return "Z";
                case '赵': return "Z";
                case '周': return "Z";
                default: return null;
            }
        }
    }
}

